package com.example.client.test.controller;

import com.example.client.test.domain.User;
import com.example.client.test.service.UserService;
import com.web.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/user")
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/list")
    public Result listAllUser(){
        List<User> allUsere = userService.getAllUser();
        return Result.success(allUsere);
    }

    @GetMapping("redis/{key}")
    public Result getRedis(@PathVariable("key")String key){
        String result = (String) redisTemplate.opsForValue().get(key);
        return Result.success(result);
    }
}
